﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public partial class frmPlayerSimulator : Form
    {
        public frmPlayerSimulator()
        {
            InitializeComponent();
        }

        private void btnStartSending_Click(object sender, EventArgs e)
        {
          
                 if (!this.tmrPeriodicSender.Enabled)
                 {
                     this.tmrPeriodicSender.Enabled = true;
                     this.btnStartSending.Text = "Sending";
                 }
                 else
                 {
                     this.tmrPeriodicSender.Enabled = false;
                     this.btnStartSending.Text = "Start";
                 }
             
        }

        private void tmrPeriodicSender_Tick(object sender, EventArgs e)
        {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            IPAddress serverAddr = IPAddress.Parse(this.txtIP.Text);

            IPEndPoint endPoint = new IPEndPoint(serverAddr, int.Parse(this.txtBasePort.Text) + int.Parse(this.txtPlayerId.Text));

            string text = "<Location=100,200;status=ALIVE;HasFlag=FALSE>";
            byte[] send_buffer = Encoding.ASCII.GetBytes(text);

            sock.SendTo(send_buffer, endPoint);

        }
    }
}
